package com.tasks.table;

import org.apache.log4j.Logger;
import com.tasks.enums.*;
import com.tasks.server.*;

public class Task extends Table {
	
	static Logger logger = Logger.getLogger(Task.class); 
	
	private static final Column user 		= new Column("USER", Column.TABLE);
	private static final Column priority 	= new Column("PRIORITY", Column.ENUM);
	private static final Column location 	= new Column("LOCATION", Column.ENUM);
	
	private static final Column columns[] 	= new Column[]
    {
		user,
		priority,
		location
	};
	
	public Task(Server server, Executor exe)
	{
		super(server, exe, columns);
	}
	
	public Task(User usr, Priority pri, Location loc)
	{
		addColumn(user, usr);
		addColumn(priority, pri);
		addColumn(location, loc);
	}
	
	public static Column[] getColumns()
	{
		return columns;
	}
	
	public static Task fetchById(Server server, Integer id)
	{
		Executor executor = new Executor(server);
		Task task = null;
		
		String sql = "SELECT * " 
				   + "FROM TASK "
				   + "WHERE TASKID = " + id + ";";
		
		if(executor.execute(sql))
		{
			task = new Task(server, executor);
		}
		executor.close();
		executor = null;
		
		return task;
	}
}
